const {artcle} = require('./manager/artcle')
// 创建express服务器
const express = require('express');
const app = express();
// const router = require('./router/user/register')
// const routerLogin = require('./router/user/login')
// const main = require('./router/main')
// const jwt = require('jsonwebtoken')
require('./db/db')

app.use(express.urlencoded({extended:false}))

// app.use('/api', router)
// app.use('/api', routerLogin)
// app.use('/api', main)

// 设置跨域和相应数据格式  
app.all('*', function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, mytoken')
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, Authorization')
    res.setHeader('Content-Type', 'application/json;charset=utf-8')
    res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With')
    res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
    res.header('X-Powered-By', ' 3.2.1')
    next()
})
app.get('/', (req, res)  => {
  res.json({code: 2000, msg: '成功'})
})
app.get('/artclelist', (req, resp) => {
  const pageNum = req.query.pageNum
  artcle.getList(pageNum).then( res => {
    artcle.count().then(res1=> {
         resp.json({code: 2000, msg: '添加成功', data: {data:res, count: res1.count}})
     })
  }).catch(err => {
      resp.json({code: 2003, msg: '操作失败，请稍后再试'})
  })
})



// 监听3000 端口
app.listen(3000,function(){
    console.log('正在监听3000端口...');
})